﻿namespace Sedodream.Web.Common.Exceptions
{
    using System;
    using System.Collections.Generic;

    [global::System.Serializable]
    public class ValidationException : Exception
    {
        public ValidationException() : this(null, null) 
        {
        }
        
        public ValidationException(string message) : this(message, null) 
        { 
        }
        
        public ValidationException(string message, Exception inner) : base(message, inner) 
        {
            ValidationErrors = new List<KeyValuePair<string, string>>();
        }

        protected ValidationException(
          System.Runtime.Serialization.SerializationInfo info,
          System.Runtime.Serialization.StreamingContext context)
            : base(info, context) 
        {
            ValidationErrors = new List<KeyValuePair<string, string>>();
        }

        public IList<KeyValuePair<string, string>> ValidationErrors { get; set; }

        public void AddValidationError(string key, string value)
        {
            if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); }
            if (string.IsNullOrEmpty(value)) { throw new ArgumentNullException("value"); }

            this.ValidationErrors.Add(new KeyValuePair<string, string>(key, value));
        }
    }
}
